# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Yejun Yang <yejunx AT gmail DOT com>
# Contributor: Michal Krenek <mikos@sg1.cz>

pkgbase=libsrtp
pkgname=(libsrtp libsrtp-docs)
pkgver=2.5.0
pkgrel=1
epoch=1
pkgdesc="Library for SRTP (Secure Realtime Transport Protocol)"
url="https://github.com/cisco/libsrtp"
arch=(x86_64)
license=(BSD)
depends=(nss)
makedepends=(
  doxygen
  git
  libpcap
  meson
)
checkdepends=(procps-ng)
_commit=a566a9cfcd619e8327784aa7cff4a1276dc1e895  # tags/v2
source=("git+https://github.com/cisco/libsrtp#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd libsrtp
  git describe --tags | sed 's/^v//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd libsrtp

  # Fixup pkgver: There are proper tags like v2.4.4
  # but also "moving tags" like v2 and v2.4 that aren't stable
  git tag | grep -Pv '^v\d+\.\d+\.\d+$' | xargs git tag -d
}

build() {
  local meson_options=(
    --buildtype release
    -D crypto-library=nss
    -D crypto-library-kdf=disabled
  )

  arch-meson libsrtp build "${meson_options[@]}"
  meson compile -C build
  meson compile -C build doc
}

check() {
  meson test -C build --print-errorlogs
}

package_libsrtp() {
  provides=("libsrtp${pkgver%%.*}.so")

  meson install -C build --destdir "$pkgdir"
  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 libsrtp/LICENSE
}

package_libsrtp-docs() {
  pkgdesc+=" (documentation)"
  depends=()

  mkdir -p "$pkgdir/usr/share/doc"
  cp -a build/html "$pkgdir/usr/share/doc/libsrtp"

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 libsrtp/LICENSE
}

# vim:set sw=2 sts=-1 et:
